import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入table-tree插件
import tabletree from 'vue-table-with-tree-grid'

Vue.component('table-tree',tabletree)
Vue.use(VueRouter)
// import { component } from 'vue/types/umd'
// import Login from 'components/Login'

const routes = [
  { path:'/', redirect:'/Login'},
  { path: '/Login',component: () => import('components/Login') },
  { path: '/Home',component: () => import('views/Home'),redirect:'/welecom',
  children:[
      {path:'/welecom',component:()=>import('components/welecom')},
      {path:'/users',component:()=>import('components/users/User')},
      {path:'/rights',component:()=>import('components/rights/Rights')},
      {path:'/roles',component:()=>import('components/roles/Roles')},
      {path:'/categories',component:()=>import('components/goods/Category')}
  ] }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 挂载路由导航权限守卫
router.beforeEach((to,from,next)=>{
   if(to.path==='/Login') return next()
  //  判断是否有token，有就next()放行，没有强制跳转到/Login
   const tokenstring=window.sessionStorage.getItem('token')
   if(!tokenstring) return next('/Login')
   next()
})


export default router
